home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / stk-3.002 / stk-3 / STk-3.1 / Lib / dialog.stk < prev    next >
Encoding:
Text File  |  1996-07-07  |  4.9 KB  |  146 lines

  1. ;;;;
  2. ;;;; Dialog box creation utility
  3. ;;;;
  4. ;;;; Copyright ⌐ 1993-1996 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
  5. ;;;; 
  6. ;;;; Permission to use, copy, and/or distribute this software and its
  7. ;;;; documentation for any purpose and without fee is hereby granted, provided
  8. ;;;; that both the above copyright notice and this permission notice appear in
  9. ;;;; all copies and derived works.  Fees for distribution or use of this
  10. ;;;; software or derived works may only be charged with express written
  11. ;;;; permission of the copyright holder.  
  12. ;;;; This software is provided ``as is'' without express or implied warranty.
  13. ;;;;
  14. ;;;; This software is a derivative work of other copyrighted softwares; the
  15. ;;;; copyright notices of these softwares are placed in the file COPYRIGHTS
  16. ;;;;
  17. ;;;;
  18. ;;;;           Author: Erick Gallesio [eg@unice.fr]
  19. ;;;;    Creation date:  4-Aug-1993 11:05
  20. ;;;; Last file update:  7-Jul-1996 11:34
  21. ;;;;
  22.  
  23. (provide "dialog")
  24.  
  25. (define stk::button-pressed   #f)
  26. ;;
  27. ;; STk:make-dialog
  28. ;;
  29. ;; This procedure displays a dialog box following the spcifications given in
  30. ;; arguments. Arguments are given as keywords.
  31. ;;
  32. ;; window (.dialog)    Window name to use for dialog top-level.
  33. ;; title ("Dialog")    Title to display in dialog's decorative frame.
  34. ;; text ("")        Message to display in dialog.
  35. ;; bitmap ("")        Bitmap to display in dialog (empty string means none).
  36. ;; default (-1)     Index of button that is to display the default ring
  37. ;;            (-1 means none).
  38. ;; grab (#f)        Indicates if make-dialog must wait that a button be
  39. ;;            pressed before returning. Use 'global to heve a global
  40. ;;            grab.
  41. ;; buttons ('())    A list of couples indicating the button text and its
  42. ;;            associated action (a closure)
  43. ;;
  44. ;; If grabbing is set, this procedure returns the button pressed index.
  45. ;;
  46.  
  47. (define (STk:make-dialog . arguments)
  48.   (let ((w        (get-keyword :window  arguments '.dialog))
  49.     (title       (get-keyword :title   arguments "Dialog"))
  50.     (text       (get-keyword :text    arguments ""))
  51.     (bitmap    (get-keyword :bitmap  arguments ""))
  52.     (default   (get-keyword :default arguments -1))
  53.     (grabbing  (get-keyword :grab    arguments #f))
  54.     (buttons   (get-keyword :buttons arguments '()))
  55.     (old-focus (Tk:focus)))
  56.  
  57.     (catch (Tk:destroy w))
  58.  
  59.     ;; 1. Create the top-level window and divide it into top and bottom parts.
  60.     (define w.top (format #f "~A.top" w))
  61.     (define w.bot (format #f "~A.bot" w))
  62.     (define w.msg (format #f "~A.top.msg" w))
  63.     (define w.bmp (format #f "~A.top.bmp" w))
  64.  
  65.     (Tk:toplevel w :class "Dialog")
  66.     (Tk:wm 'title w title)
  67.     (Tk:wm 'iconname w "Dialog")
  68.     
  69.     (Tk:pack [Tk:frame w.top :relief "raised" :bd 1] :expand #t :fill "both")
  70.     (Tk:pack [Tk:frame w.bot :relief "raised" :bd 1] :fill "x")
  71.  
  72.     ;; 2. Fill the top part with bitmap and message (use the option
  73.     ;;    database for -wraplength so that it can be overridden by
  74.     ;;    the caller).
  75.  
  76.     (option 'add "*Dialog.msg.wrapLength" "3i" "widgetDefault")
  77.     (Tk:pack [label w.msg :justify "left" :text text 
  78.             :font "-Adobe-Times-Medium-R-Normal-*-180-*"]
  79.          :side "right"
  80.          :expand #t 
  81.          :padx 10
  82.          :pady 10
  83.          :fill "both")
  84.  
  85.     (unless (equal? bitmap "")
  86.     (Tk:pack [Tk:label w.bmp :bitmap bitmap :fg "red"]
  87.          :side "left"
  88.          :padx 10
  89.          :pady 10))
  90.  
  91.     ;; 3. Create a row of buttons at the bottom of the dialog.
  92.     (do ([i 0 (+ i 1)] [but buttons (cdr but)])
  93.     ([null? but] '())
  94.       
  95.       (let ((name (format #f "~A.but-~A" w  i)))
  96.     (Tk:button name :text (caar but) 
  97.                :command (lambda ()
  98.                    (if old-focus (Tk:focus old-focus))
  99.                    (set! stk::button-pressed i)
  100.                    (Tk:destroy w)
  101.                    (apply (cadar but) '())))
  102.     (if (equal? i default)
  103.         (Tk:focus name))
  104.     (Tk:pack name :side "left" :expand #t :padx 20 :pady 8 :ipadx 2 :ipady 2)))
  105.  
  106.     ;; 4. Center window
  107.     (STk:center-window w)
  108.  
  109.     ;; 5. Wait until a button is pressed if grab is set 
  110.     (when grabbing
  111.       (let* ((old-grab    (Tk:grab 'current *root*))
  112.          (grab-status (if old-grab
  113.                   (grab 'status old-grab)
  114.                   #f)))
  115.     (if (eqv? grabbing 'global) 
  116.         (Tk:grab :global '.dialog)
  117.         (Tk:grab 'set w))
  118.     (Tk:tkwait 'variable 'stk::button-pressed)
  119.     (if old-grab
  120.         (if (equal? grab-status "global")
  121.         (Tk:grab :global old-grab)
  122.         (Tk:grab old-grab))))
  123.     stk::button-pressed)))
  124.  
  125.  
  126. (define (STk:center-window w)
  127.   ;; Withdraw the window, then update all the geometry information
  128.   ;; so we know how big it wants to be, then center the window in the
  129.   ;; display and de-iconify it.
  130.  
  131.   (wm 'withdraw w)
  132.   (update 'idletasks)
  133.   (let ((x (- (/ [winfo 'screenwidth w] 2) 
  134.           (/ [winfo 'reqwidth w] 2)
  135.           (winfo 'vrootx [eval [winfo 'parent w]])))
  136.     (y (- (/ [winfo 'screenheight w] 2)
  137.           (/ [winfo 'reqheight w] 2)
  138.           (winfo 'vrooty [eval [winfo 'parent w]]))))
  139.     (wm 'geom w (format #f "+~A+~A" (inexact->exact (floor x)) 
  140.                     (inexact->exact (floor y))))
  141.     (wm 'deiconify w)))
  142.  
  143.  
  144. ;;;;; Compatibility
  145. (define stk::make-dialog STk:make-dialog)
  146.